/**
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.solarchallenge.shared.dtos;

/**
 * DTO for UsAddress.
 *
 * @author Arjun Satyapal
 */
public class UsAddressDto implements AbstractDto {
  private long id;
  private String address1;
  private String address2;
  private String city;
  private String state;
  private String zip;

  @Override
  public StringBuilder getStringBuilder() {
    StringBuilder builder = new StringBuilder("UsAddressDto[");
    builder.append("id:").append(id);
    builder.append(", address1:").append(address1);
    builder.append(", address2:").append(address2);
    builder.append(", city:").append(city);
    builder.append(", state:").append(state);
    builder.append(", zip:").append(zip);
    builder.append("].");

    return builder;
  }

  @Override
  public String toString() {
    return getStringBuilder().toString();
  }

  private UsAddressDto() {
  }

  @Override
  public String validate() {
    StringBuilder builder = new StringBuilder("");

    // id will be set only by server. So not checking it.
    if (address1.isEmpty()) {
      builder.append("address1 is empty.\n");
    }
    if (address2.isEmpty()) {
      builder.append("address2 is empty.\n");
    }
    if (city.isEmpty()) {
      builder.append("city is empty.\n");
    }
    if (state.isEmpty()) {
      builder.append("state is empty.\n");
    }
    if (zip.isEmpty()) {
      builder.append("zip is empty.\n");
    }
    return builder.toString();
  }

  public long getId() {
    return id;
  }

  public String getAddress1() {
    return address1;
  }

  public String getAddress2() {
    return address2;
  }

  public String getCity() {
    return city;
  }

  public String getState() {
    return state;
  }

  public String getZip() {
    return zip;
  }

  public static class Builder {
    private long id;
    private String address1;
    private String address2;
    private String city;
    private String state;
    private String zip;

    public Builder setId(long id) {
      this.id = id;
      return this;
    }

    public Builder setAddress1(String address1) {
      this.address1 = address1;
      return this;
    }

    public Builder setAddress2(String address2) {
      this.address2 = address2;
      return this;
    }

    public Builder setCity(String city) {
      this.city = city;
      return this;
    }

    public Builder setState(String state) {
      this.state = state;
      return this;
    }

    public Builder setZip(String zip) {
      this.zip = zip;
      return this;
    }

    public UsAddressDto build() {
      UsAddressDto dto = new UsAddressDto();
      dto.id = this.id;
      dto.address1 = this.address1;
      dto.address2 = this.address2;
      dto.city = this.city;
      dto.state = this.state;
      dto.zip = this.zip;
      dto.validate();
      return dto;
    }
  }
}
